package org.bing.flex.action {
    import mx.collections.ArrayCollection;
    import mx.controls.Alert;
    import mx.rpc.IResponder;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;

    import org.bing.flex.error.ErrorManager;

    public class HessianResponder implements IResponder {

        private var _result:Function;
        private var _fault:Function;

        private var debug:Boolean=false;

        public function HessianResponder(result:Function=null, fault:Function=null) {
            this._result=result;
            this._fault=fault;
        }

        public function result(result:Object):void {
            var data:Object=result.result;
            if (data is Array) {
                data=new ArrayCollection(data as Array);
            }
            if (this._result != null) {
                this._result(data);
            } else {
                trace("RES " + data);
            }
        }

        public function fault(info:Object):void {
            if (info is FaultEvent) {
                ErrorManager.fault(info as FaultEvent);
            }
            if (this._fault != null) {
                this._fault(info);
            } else {
                trace("ERR " + info);
            }
        }

    }
}